package cn.fudong.bos.action.transit;

import java.util.HashMap;
import java.util.Map;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Controller;

import cn.fudong.bos.action.commom.BaseAction;
import cn.fudong.bos.domain.tranist.TransitInfo;
import cn.fudong.bos.service.transit.TransitInfoService;

/**
 * 
 * @description:中转运输管理
 * @author ：d_fu
 * @date 创建时间：2018年3月31日 上午8:25:19
 *
 */

@ParentPackage("json-default")
@Namespace("/")
@Controller
@Scope("prototype")
public class TransitInfoAction extends BaseAction<TransitInfo> {

	@Autowired
	private TransitInfoService transitinfoservice;

	private String wayBillIds;

	public void setWayBillIds(String wayBillIds) {
		this.wayBillIds = wayBillIds;
	}

	// 创建中转
	@Action(value = "transit_create", results = { @Result(name = "success", type = "json") })
	public String create() {

		Map<String, Object> result = new HashMap<String, Object>();

		try {
			transitinfoservice.createTransitions(wayBillIds);
			// 保存成功
			result.put("success", true);
			result.put("msg", "开启中转配送成功!");

		} catch (Exception e) {
			e.printStackTrace();
			result.put("success", false);
			result.put("msg", "开启中转配送失败" + e.getMessage());
		}

		pushDataToValueStack(result);
		return SUCCESS;

	}
	//分页查询
	@Action(value = "transit_pageQuery", results = { @Result(name = "success", type = "json") })
	public String pageQuery() {
		
		Pageable pageable =new PageRequest(page-1,rows); 
		Page<TransitInfo>pageData=transitinfoservice.findAll(pageable);
		
		pushPageDataToValueStack(pageData);
		
		return SUCCESS;
		
		
	}
	
}		
